package com.example.demo.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;


@ControllerAdvice
public class ErrorAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object exceptionAdvice(Exception e) {
        HashMap<String,Object> result = new HashMap<>();
        result.put("msg",e.getMessage());
        result.put("code",-100);
        return result;
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Object arithmeticExceptionAdvice(ArithmeticException e) {
        HashMap<String,Object> result = new HashMap<>();
        result.put("msg",e.getMessage());
        result.put("code",-2);
        return result;
    }
}